<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.ui.core.js"></script>
<script type="text/javascript" src="../js/jquery.ui.datepicker.js"></script>
<link href="../style/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
<link href="../style/cs1.css" rel="stylesheet" type="text/css" />

<script>
$(document).ready(function() {
$("#ngaynhap").datepicker({
numberOfMonths: 1,  dateFormat: 'yy/mm/dd',
monthNames: ['Một','Hai','Ba','Tư','Năm','Sáu','Bảy','Tám','Chín', 
'Mười','Mười một','Mười hai'] ,
monthNamesShort: ['Tháng1','Tháng2','Tháng3','Tháng4','Tháng5',
'Tháng6','Tháng7','Tháng8','Tháng9','Tháng10','Tháng11','Tháng12'] ,
dayNames: ['Chủ nhật', 'Thứ hai', 'Thứ ba', 'Thứ tư', 'Thứ năm',
 'Thứ sáu', 'Thứ bảy'],
dayNamesMin: ['CN', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7'] ,
showWeek: true , showOn: 'both',
changeMonth: true , changeYear: true,
currentText: 'Hôm nay', weekHeader: 'Tuần'
});
});
</script>
<script>
{
	function nhapsonguyen(e)
	{
		var keyword = null;
		if(window.event)
		{
			keyword = window.event.keyCode;	
		}
		else
		{
			keyword = e.which;	
		}
		
		if(keyword<48 || keyword>57)
		{
			if(keyword==48 || keyword==127)
			{
				return;	
			}
			return false;
		}
		
	}
	
}
</script>
<script>
{
	function nhapnoibat(e)
	{
		var keyword = null;
		if(window.event)
		{
			keyword = window.event.keyCode;	
		}
		else
		{
			keyword = e.which;	
		}
		
		if(keyword<48 || keyword>49)
		{
			if(keyword==48 || keyword==127)
			{
				return;	
			}
			return false;
		}
		
	}
	
}
</script>

</head>

<body>
<?php
$idsua = $_GET["idsua"];
include("../config/config.php");
$malaptop = $_POST["malaptop"];
$tenlaptop = $_POST["tenlaptop"];
$hang = $_POST["hang"];
$loai = $_POST["loai"];
$mota = $_POST["mota"];
$soluong = $_POST["soluong"];
$dongia = $_POST["dongia"];
$hinh = $_FILES["hinh"]["name"];
$ngaynhap = $_POST["ngaynhap"];
$noibat = $_POST["noibat"];
$lenh = "select * from laptop where malaptop='$idsua'";
$kq = mysql_query($lenh);
$row = mysql_fetch_array($kq);

if(isset($_POST["sua"]))
{
	if($_FILES["hinh"]["name"]!="")
	{
$lenhsua = "update laptop set malaptop='$malaptop',tenlaptop='$tenlaptop',mahanglaptop='$hang',maloailaptop='$loai',mota='$mota',soluong='$soluong',dongia='$dongia',hinh='$hinh',ngaynhap='$ngaynhap',noibat='$noibat' where malaptop='$idsua'";
	}
	else
	{
		$lenhsua = "update laptop set malaptop='$malaptop',tenlaptop='$tenlaptop',mahanglaptop='$hang',maloailaptop='$loai',mota='$mota',soluong='$soluong',dongia='$dongia',ngaynhap='$ngaynhap',noibat='$noibat' where malaptop='$idsua'";
	}
$kqsua = mysql_query($lenhsua);
move_uploaded_file($_FILES["hinh"]["tmp_name"],"../laptop/".$_FILES["hinh"]["name"]);
if($kqsua)
{
	?>
    <script>
	alert('sửa thành công!');
	location.href='indexqt.php?act=thongtinlaptop.php';
	</script>
   <?php
  
	
}

}
?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table width="600" border="1" align="center" cellpadding="0" cellspacing="0" class="manh">
    <tr>
      <td height="35" colspan="2" align="center" bgcolor="#FFFF99" class="dangkythanhvien"><strong>Sửa Laptop</strong></td>
    </tr>
    <tr>
      <td width="230" height="30"><strong>Malaptop</strong></td>
      <td width="364" height="30"><label for="malaptop"></label>
      <input name="malaptop" type="text" class="onhapdangkyvua" id="malaptop" value="<?php  echo $idsua;   ?>" readonly="readonly" /></td>
    </tr>
    <tr>
      <td height="30"><strong>Tên laptop</strong></td>
      <td height="30"><label for="tenlaptop"></label>
      <textarea name="tenlaptop" rows="3" class="mota" id="tenlaptop"><?php  echo $row["Tenlaptop"];   ?>
        </textarea></td>
    </tr>
    <tr>
      <td height="30"><strong>Hãng</strong></td>
      <td height="30"><label for="hang"></label>
        <select name="hang" class="onhapdangkyvua" id="hang">
        
        <?php
		$lenhhang = "select * from hanglaptop";
		$kqhang = mysql_query($lenhhang);
		while($rowhang = mysql_fetch_array($kqhang))
		{
			if($row["Mahanglaptop"]==$rowhang[0])
			echo "<option value='$rowhang[0]' selected>$rowhang[1]</option>";
			else
			echo "<option value='$rowhang[0]'>$rowhang[1]</option>";
		}
		?>
        
      </select></td>
    </tr>
    <tr>
      <td height="30"><strong>Loại</strong></td>
      <td height="30"><label for="loai"></label>
        <select name="loai" class="onhapdangkyvua" id="loai">
        
        <?php
		$lenhloai = "select * from loailaptop";
		$kqloai = mysql_query($lenhloai);
		while($rowloai = mysql_fetch_array($kqloai))
		{
			if($row["Maloailaptop"]==$rowloai[0])
			echo "<option value='$rowloai[0]' selected>$rowloai[1]</option>";
			else
			echo "<option value='$rowloai[0]'>$rowloai[1]</option>";
		}
		?>
      </select></td>
    </tr>
    <tr>
      <td height="30"><strong>Mô tả</strong></td>
      <td height="30"><label for="mota"></label>
      <textarea name="mota" rows="4" class="mota" id="mota"><?php  echo $row["Mota"];   ?>
        </textarea></td>
    </tr>
    <tr>
      <td height="30"><strong>Số lượng</strong></td>
      <td height="30"><label for="soluong"></label>
      <input name="soluong" type="text" onkeypress="return nhapsonguyen(event); "  class="onhapdangkyvua" id="soluong" value="<?php  echo $row["Soluong"];   ?>"/></td>
    </tr>
    <tr>
      <td height="30"><strong>Đơn giá</strong></td>
      <td height="30"><label for="dongia"></label>
      <input name="dongia" type="text" onkeypress="return nhapsonguyen(event); " class="onhapdangkyvua" id="dongia" value="<?php  echo $row["Dongia"];   ?>"/></td>
    </tr>
    <tr>
      <td height="30"><strong>Hình</strong></td>
      <td height="30"><label for="hinh"></label>
      <input name="hinh" type="file" class="onhapdangkyvua" id="hinh" /></td>
    </tr>
    <tr>
      <td height="30"><strong>Ngày nhập</strong></td>
      <td height="30"><label for="ngaynhap"></label>
      <input name="ngaynhap" type="text" class="onhapdangkyvua" id="ngaynhap" value="<?php  echo $row["Ngaynhap"];   ?>"/></td>
    </tr>
    <tr>
      <td height="30"><strong>Nổi Bật</strong></td>
      <td height="30"><input name="noibat" onkeypress="return nhapnoibat(event); " placeholder="Nổi bật nhập 0 hoặc 1" type="text" class="onhapdangkyvua" id="noibat" value="<?php  echo $row["Noibat"];   ?>"/> </td>
    </tr>
    <tr>
      <td height="30" colspan="2" align="center"><input name="sua" type="submit" class="nuttim" id="sua" value="Sửa laptop" /></td>
    </tr>
  </table>
</form>
</body>
</html>